#include "settings.h"
#include "event_filters.h"

#include <QDoubleSpinBox>
#include <QGridLayout>
#include <QLineEdit>
#include <QSpinBox>

/************
 * Settings *
 ************/

Settings::Settings( QWidget * parent )
    : QWidget( parent ) {
    QGridLayout * gridLayout = new QGridLayout{ this };
    gridLayout->setSpacing( 0 );

    // event tier
    tier = new QDoubleSpinBox{ this };
    tier->setAlignment( Qt::AlignHCenter );
    tier->setSizePolicy( QSizePolicy::Policy::Preferred, QSizePolicy::Policy::Fixed );
    tier->sizeHint();
    tier->setMaximum( 9 );
    tier->setMinimum( 0 );
    tier->setSingleStep( 0.1 );
    tier->setPrefix( "Event Tier: " );
    tier->installEventFilter(new SelectAllOnFocusIn{this});
    connect( tier, QOverload<double>::of( &QDoubleSpinBox::valueChanged ), this, &Settings::tierChanged );
    connect( tier->findChild<QLineEdit *>(), &QLineEdit::returnPressed, tier, &QWidget::clearFocus );
    connect( tier->findChild<QLineEdit *>(), &QLineEdit::returnPressed, tier->findChild<QLineEdit *>(), &QLineEdit::deselect, Qt::QueuedConnection );

    // playthrough
    playthrough = new QSpinBox{ this };
    playthrough->setMaximum( 9 );
    playthrough->setMinimum( 1 );
    playthrough->setPrefix( "Playthrough # " );
    playthrough->setAlignment( Qt::AlignHCenter );
    playthrough->installEventFilter(new SelectAllOnFocusIn{this});
    connect( playthrough, QOverload<int>::of( &QSpinBox::valueChanged ), this, &Settings::playthroughChanged );
    connect( playthrough->findChild<QLineEdit *>(), &QLineEdit::returnPressed, playthrough, &QWidget::clearFocus );
    connect( playthrough->findChild<QLineEdit *>(), &QLineEdit::returnPressed, playthrough->findChild<QLineEdit *>(), &QLineEdit::deselect, Qt::QueuedConnection );

    gridLayout->addWidget( tier, 0, 0 );
    gridLayout->addWidget( playthrough, 1, 0 );
}
